﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Public;

namespace DAL
{
    public class PhuongXaDAL
    {
        public static List<PhuongXaPublic> loadPhuongXa()
        {
            var phuongxa = Common.db.ExecuteStoreQuery<PhuongXaPublic>(@"select * from PhuongXa");
            return phuongxa.ToList();
        }
        public static List<PhuongXaPublic> loadPhuongXaByMaQH(int MaQH)
        {
            var phuongxa = Common.db.ExecuteStoreQuery<PhuongXaPublic>(@"select * from PhuongXa where MaQH=" + MaQH);
            return phuongxa.ToList();
        }
        public static void InsertPhuongXa(PhuongXaPublic _px)
        {
            PhuongXa px = new PhuongXa();
            px.MaPX=_px.MaPX;
            px.TenPhuongXa=_px.TenPhuongXa;
            Common.db.AddToPhuongXas(px);
            Common.db.SaveChanges();
        }
        public static PhuongXaPublic UpdatePhuongXa(int MaPX, string TenPhuongXa)
        {
            var phuongxa = Common.db.ExecuteStoreQuery<PhuongXaPublic>("update PhuongXa set TenPhuongXa=" + "'" + TenPhuongXa + "'" + "where MaPX=" + MaPX);
            return phuongxa.FirstOrDefault();
        }
        public static int LoadMaPX()
        {
            var px = Common.db.ExecuteStoreQuery<int>("select ISNULL(MAX(MaPX),0) from PhuongXa");
            return px.FirstOrDefault();
        }
    }
}
